<?php

namespace app\adm\controller;
// use think\Db;

class Nsuser extends Base {
	// 玩家列表
	public function index() {
		if (is_post()) {
			$act = input('get.act');
			switch ($act) {
			case 'status':
				return model('Nsuser')->changeStatus(input('post.id'));
				break;
			case 'reset':
				return model('Nsuser')->resetPwd(input('post.id'));
				break;
			case 'todel':
				$rst = db('ns_user')->where('id',input('post.id'))->update(['del_status'=>0]);
				if ($rst) $this->success('删除成功');$this->error('请稍后再试');
			case 'get':
				return model('Nsuser')->getTeam(['id' => input('post.id')])->items()[0];
				break;
			case 'edbase':
				$post = input('post.');
				$validate = validate('Vnsuser');
				$rst = $validate->scene('addUser')->check($post);
				return model('Nsuser')->editInfo($post, $post['id']);
				break;
			case 'edbasic':
				$post = input('post.');
				$validate = validate('Vnsuser');
				$rst = $validate->scene('cardId')->check($post);
				$post['perfect'] = 1;
				return model('Nsuser')->edbasic($post, $post['id']);
				break;
			case 'funds':
				$post = input('post.');
				$id = $post['id'];
				unset($post['id']);
				foreach ($post as $v) {
					if (!is_numeric($v)) {
						return ['code' => 0, 'msg' => '请输入数字'];
					}
				}
				$post['total_funds'] = $post['available_funds'] + $post['commission'] + $post['settlemen_funds'];
				return model('Nsuser')->edbasic($post, $id);
				break;
			case 'add':
				$post = input('post.');
				$validate = validate('Vnsuser');
				$rst = $validate->scene('addUser')->check($post);
				if (!$rst) {
					$this->error($validate->getError());
				} else {
					return model('Nsuser')->addInfo($post);
				}
				break;
			default:
				break;
			}
		}

		$map = [];
		$order = '';
		$group = array();
		$group = db('ns_user_group')->select();
		$groupname = [];
		if (!empty($group)) {
			foreach ($group as $k => $v) {
				$groupname[$v['id']] = $v['group_name'];
			}
		}
		$this->assign('group', $groupname);
		$list = model('nsuser')->getList($map);
		$this->assign('list', $list);
		return $this->fetch();
	}

	// 商家列表
	/*	public function shop()
	{
		if (is_post()) {

		}

		$map['is_shop'] = 1;
		$order = '';
		if (is_get()) {
			if (input('get.keywords')) {
				$map['name|tel'] = ['like','%'.input('get.keywords').'%'];
			}
			if (is_numeric(input('get.status'))) {
				$map['status'] = input('get.status');
			}

			if (input('get.pid')) {
				$map['pid'] = input('get.pid');
			}

			if (input('get.province')) {
				$map['province'] = input('get.province');
			}

			if (input('get.city')) {
				$map['city'] = input('get.city');
			}

			if (input('get.order')) {
				$order = input('get.order').' DESC';
			} else {
				$order = 'user.create_time DESC';
			}
		}

		$list = model('User')->getList($map);

		$this->assign('list', $list);

		return $this->fetch();
	}*/

	// 会员账户明细
	public function userAcclog() {
		$list = \think\Db::view('user_account_records', '*')
			->view('ns_user', 'username,mobile', 'user_account_records.uid=ns_user.id')
			->order('create_time DESC')
			->paginate();
		$this->assign('list', $list);
		return $this->fetch();
	}

}